﻿package com.kuanter.kuanterauto.adapter;

import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.entity.ConsumerLog;

public class ConsumerLogListAdapter extends BaseAdapter {
	private List<ConsumerLog> consumerLogList ;
	private Activity activity ;
	private TextView include_my_consumer_log_kind;
	private TextView include_my_consumer_log_time;
	private TextView include_my_consumer_log_money;
	private TextView include_my_consumer_log_status;
	
	public ConsumerLogListAdapter(List<ConsumerLog> consumerLogList,Activity activity) {
		this.consumerLogList = consumerLogList;
		this.activity = activity;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return consumerLogList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return consumerLogList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null ;
		if(null == convertView){
			view = View.inflate(activity, R.layout.my_consumer_log_item, null);
		}else {
			view = convertView;
		}
		//init 条目控件
		include_my_consumer_log_kind = (TextView) view.findViewById(R.id.include_my_consumer_log_kind);
		include_my_consumer_log_time = (TextView) view.findViewById(R.id.include_my_consumer_log_time);
		include_my_consumer_log_money = (TextView) view.findViewById(R.id.include_my_consumer_log_money);
		include_my_consumer_log_status = (TextView) view.findViewById(R.id.include_my_consumer_log_status);
		//给数据
		include_my_consumer_log_kind.setText(consumerLogList.get(position).getConsumptionType());
		include_my_consumer_log_time.setText(consumerLogList.get(position).getConsumptionTime());
		include_my_consumer_log_money.setText(consumerLogList.get(position).getConsumptionAmount());
		if(null == consumerLogList.get(position).getState()){
			include_my_consumer_log_status.setText("成功");
		}else {
			switch (Integer.valueOf(consumerLogList.get(position).getState())) {
			case 1:
				include_my_consumer_log_status.setText("处理中");
				break;
			case 4:
				include_my_consumer_log_status.setText("已完成");
//				include_my_consumer_log_status.setBackgroundResource(android.R.color.transparent);
//				include_my_consumer_log_status.setTextColor(activity.getResources().getColor(R.color.consumer_state));
				break;
			case 9:
				include_my_consumer_log_status.setText("已取消");
				break;
			}
		}
		return view;
	}

}
